#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project ：NoBad 
@File    ：view.py
@Author  ：LYP
@Date    ：2025/10/30 13:26 
@description :
"""
from drf_spectacular.utils import extend_schema, extend_schema_view
from rest_framework import serializers

from models.models import WxSetting
from tool.base_views import BaseViewSet


class SystemConfigSerializer(serializers.ModelSerializer):
    """
    系统配置序列化器
    """

    class Meta:
        model = WxSetting
        fields = '__all__'
        read_only_fields = ('created_time', 'updated_time')


@extend_schema(tags=["小程序通知"])
@extend_schema_view(
    list=extend_schema(
        summary="获取小程序通知",
        description="返回所有提示词的信息列表",
        responses={200: SystemConfigSerializer(many=True)},
    ),
    create=extend_schema(
        summary="创建小程序通知",
        description="创建一个新的提示词",
        request=SystemConfigSerializer,
        responses={201: SystemConfigSerializer},
    )
)
class SystemConfigView(BaseViewSet):
    """
    系统配置视图
    """
    serializer_class = SystemConfigSerializer

    def get_queryset(self):
        # 获取查询参数
        name = self.request.GET.get('name', None)
        # 构建查询条件
        queryset = WxSetting.objects.all()
        if name:
            queryset = queryset.filter(name__icontains=name)
        return queryset

